package pseudoAssemblerCompiler.twopassassembler.model.io;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pseudoAssemblerCompiler.twopassassembler.model.entities.OperationCode;

import java.util.Map;
import java.util.TreeMap;

/**
 * User: Администратор
 * Date: 16.06.12
 * Time: 0:12
 */
public class CodeOperationTableParser implements ParserInterface {

    private static final Logger LOGGER =
            LoggerFactory.getLogger(CodeOperationTableParser.class);


    private Map<String, OperationCode> _operationCodes =
            new TreeMap<String, OperationCode>();

    @Override
    public String parseString(String stringToParse) {
        stringToParse = stringToParse.substring(0, stringToParse.length() - 1);
        String[] arr = stringToParse.split(", ");
        OperationCode code = new OperationCode();
        code.set_mnemonicCode(arr[0]);
        code.set_binaryCode(Integer.parseInt(arr[1]));
        code.set_lengthOfCommand(Integer.parseInt(arr[2]));
        code.set_typeOfAddressing(Integer.parseInt(arr[3]));
        code.set_directive(Boolean.parseBoolean(arr[4]));

        LOGGER.debug(String.valueOf("JMP".hashCode()));
        LOGGER.debug(String.valueOf(code.get_mnemonicCode().hashCode()));

        _operationCodes.put(code.get_mnemonicCode(), code);
        return "";
    }

    public Map<String, OperationCode> getCodeOperationTable() {
        return  _operationCodes;
    }
}
